Imports System.Data.SqlClient
''' <nombre>
''' Personal
''' </nombre>
Public Class cls_personal_

    Implements ICloneable

#Region "Variables ..."
    Private int_idpersonal As Integer = 0
    Private str_legajo As String = ""
    Private str_iniciales As String = ""
    Private int_idsector As Integer = 0
    Private int_idcargo As Integer = 0
    Private int_idtercero As Integer = 0
    Private dte_fechaingreso As DateTime = New System.DateTime(Now.Year, 1, 1)
    Private dte_fechaegreso As DateTime = New System.DateTime(Now.Year, 1, 1)
    Private str_numerointerno As String
    Private dec_valorhora As Decimal
    Private dte_fechanacimiento As DateTime = New System.DateTime(Now.Year, 1, 1)
    Private int_idgerencia As Integer = 0
    Private int_jornada As Integer = 0
    Private bol_contratado As Boolean = False
    Private int_idproveedor As Integer = 0
    Private int_idcentrocostoorden As Integer = 0
    Private str_observacionesinterno As String = ""
    Private str_cuño As String = ""

    Private obj_tercero As cls_tercero_ = Nothing
    Private obj_cargo As cls_cargo_ = Nothing
    Private obj_gerencia As cls_gerencia_ = Nothing
    Private obj_sector As cls_sector_ = Nothing
    Private obj_proveedor As cls_proveedor_ = Nothing
    Private obj_centrocostoorden As cls_centrocostoorden_ = Nothing

    Private col_Items As Collections.Generic.List(Of cls_personal_) = Nothing
#End Region

    Public Overrides Function ToString() As String
        Return tercero.ToString
    End Function

#Region "Propiedades ..."
    ReadOnly Property This
        Get
            Return Me
        End Get
    End Property
    ReadOnly Property ThisDescripcion As String
        Get
            Return Me.ToString
        End Get
    End Property
    ReadOnly Property pKey
        Get
            Return idpersonal
        End Get
    End Property
    ''' <id>
    ''' True
    ''' </id>
    Property idpersonal() As Integer
        Get
            idpersonal = int_idpersonal
        End Get
        Set(ByVal value As Integer)
            int_idpersonal = value
        End Set
    End Property
    ''' <nombre>
    ''' Fecha de Nacimiento
    ''' </nombre>
    Property fechanacimiento() As DateTime
        Get
            fechanacimiento = dte_fechanacimiento
        End Get
        Set(ByVal value As DateTime)
            dte_fechanacimiento = value
        End Set
    End Property
    ''' <nombre>
    ''' Legajo
    ''' </nombre>
    Property legajo() As String
        Get
            legajo = str_legajo
        End Get
        Set(ByVal value As String)
            str_legajo = value
        End Set
    End Property
    ''' <nombre>
    ''' Iniciales
    ''' </nombre>
    Property iniciales() As String
        Get
            iniciales = str_iniciales
        End Get
        Set(ByVal value As String)
            str_iniciales = value
        End Set
    End Property
    ''' <nombre>
    ''' Identificador
    ''' </nombre>
    Property idsector() As Integer
        Get
            idsector = int_idsector
        End Get
        Set(ByVal value As Integer)
            int_idsector = value
        End Set
    End Property
    ''' <nombre>
    ''' Identificador
    ''' </nombre>
    Property idcargo() As Integer
        Get
            idcargo = int_idcargo
        End Get
        Set(ByVal value As Integer)
            int_idcargo = value
        End Set
    End Property
    ''' <nombre>
    ''' Identificador
    ''' </nombre>
    Property idtercero() As Integer
        Get
            idtercero = int_idtercero
        End Get
        Set(ByVal value As Integer)
            int_idtercero = value
        End Set
    End Property
    ''' <nombre>
    ''' Fecha de Ingreso
    ''' </nombre>
    Property fechaingreso() As DateTime
        Get
            fechaingreso = dte_fechaingreso
        End Get
        Set(ByVal value As DateTime)
            dte_fechaingreso = value
        End Set
    End Property
    ''' <nombre>
    ''' Fecha de Egreso
    ''' </nombre>
    Property fechaegreso() As DateTime
        Get
            fechaegreso = dte_fechaegreso
        End Get
        Set(ByVal value As DateTime)
            dte_fechaegreso = value
        End Set
    End Property
    ''' <nombre>
    ''' Numero Interno
    ''' </nombre>
    Property numerointerno As String
        Get
            numerointerno = str_numerointerno
        End Get
        Set(ByVal value As String)
            str_numerointerno = value
        End Set
    End Property
    Property jornada As Integer
        Get
            jornada = int_jornada
        End Get
        Set(ByVal value As Integer)
            int_jornada = value
        End Set
    End Property
    Property contratado As Boolean
        Get
            contratado = bol_contratado
        End Get
        Set(ByVal value As Boolean)
            bol_contratado = value
        End Set
    End Property
    Property idproveedor As Integer
        Get
            idproveedor = int_idproveedor
        End Get
        Set(ByVal value As Integer)
            int_idproveedor = value
        End Set
    End Property
    Property idcentrocostoorden As Integer
        Get
            idcentrocostoorden = int_idcentrocostoorden
        End Get
        Set(ByVal value As Integer)
            int_idcentrocostoorden = value
        End Set
    End Property
    Property observacionesinterno As String
        Get
            observacionesinterno = str_observacionesinterno
        End Get
        Set(ByVal value As String)
            str_observacionesinterno = value
        End Set
    End Property
    ''' <importar>
    ''' True
    ''' </importar>
    Property tercero() As cls_tercero_
        Get
            If IsNothing(obj_tercero) Then
                obj_tercero = New cls_tercero_
                If Not obj_tercero.Buscar(idtercero) Then
                    obj_tercero = Nothing
                End If
            End If
            tercero = obj_tercero
        End Get
        Set(ByVal value As cls_tercero_)
            obj_tercero = value
        End Set
    End Property
    Property proveedor() As cls_proveedor_
        Get
            If IsNothing(obj_proveedor) Then
                obj_proveedor = New cls_proveedor_
                If Not obj_proveedor.Buscar(idproveedor) Then
                    obj_proveedor = Nothing
                End If
            End If
            proveedor = obj_proveedor
        End Get
        Set(ByVal value As cls_proveedor_)
            obj_proveedor = value
        End Set
    End Property
    ReadOnly Property registro() As cls_registro_
        Get
            registro = Nothing
            If Not IsNothing(tercero) Then
                If Not IsNothing(tercero.registro) Then
                    registro = obj_tercero.registro
                End If
            End If
        End Get
    End Property
    ''' <nombre>
    ''' Valor Hora
    ''' </nombre>
    Property valorhora As Decimal
        Get
            valorhora = dec_valorhora
        End Get
        Set(ByVal value As Decimal)
            dec_valorhora = value
        End Set
    End Property
    ReadOnly Property apellidonombre As String
        Get
            apellidonombre = ""
            If Not IsNothing(tercero) Then
                Return tercero.ToString
            End If
        End Get
    End Property
    ''' <importar>
    ''' True
    ''' </importar>
    Property cargo() As cls_cargo_
        Get
            If IsNothing(obj_cargo) Then
                obj_cargo = New cls_cargo_
                If Not obj_cargo.Buscar(idcargo) Then
                    obj_cargo = Nothing
                End If
            End If
            cargo = obj_cargo
        End Get
        Set(ByVal value As cls_cargo_)
            obj_cargo = value
        End Set
    End Property
    ''' <importar>
    ''' True
    ''' </importar>
    Property gerencia() As cls_gerencia_
        Get
            If IsNothing(obj_gerencia) Then
                obj_gerencia = New cls_gerencia_
                If Not obj_gerencia.Buscar(idgerencia) Then
                    obj_gerencia = Nothing
                End If
            End If
            gerencia = obj_gerencia
        End Get
        Set(ByVal value As cls_gerencia_)
            obj_gerencia = value
        End Set
    End Property
    ''' <importar>
    ''' True
    ''' </importar>
    Property sector() As cls_sector_
        Get
            If IsNothing(obj_sector) Then
                obj_sector = New cls_sector_
                If Not obj_sector.Buscar(idsector) Then
                    obj_sector = Nothing
                End If
            End If
            sector = obj_sector
        End Get
        Set(ByVal value As cls_sector_)
            obj_sector = value
        End Set
    End Property
    Property centrocostoorden() As cls_centrocostoorden_
        Get
            If IsNothing(obj_centrocostoorden) Then
                obj_centrocostoorden = New cls_centrocostoorden_
                If Not obj_centrocostoorden.Buscar(idcentrocostoorden) Then
                    obj_centrocostoorden = Nothing
                End If
            End If
            centrocostoorden = obj_centrocostoorden
        End Get
        Set(ByVal value As cls_centrocostoorden_)
            obj_centrocostoorden = value
        End Set
    End Property
    ''' <nombre>
    ''' Identificador
    ''' </nombre>
    Property idgerencia() As Integer
        Get
            idgerencia = int_idgerencia
        End Get
        Set(ByVal value As Integer)
            int_idgerencia = value
        End Set
    End Property
    Property cuño As String
        Get
            cuño = str_cuño
        End Get
        Set(ByVal value As String)
            str_cuño = value
        End Set
    End Property
    Property Items() As Collections.Generic.List(Of cls_personal_)
        Get
            Items = col_Items
        End Get
        Set(ByVal value As Collections.Generic.List(Of cls_personal_))
            col_Items = value
        End Set
    End Property
#End Region

    Private Sub CargarColeccion(ByVal obj_Reader As SqlDataReader)
        col_Items = New Collections.Generic.List(Of cls_personal_)
        While obj_Reader.Read()
            Dim Elemento As New cls_personal_
            Elemento.int_idpersonal = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idpersonal")))

            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("legajo"))) = False Then
                Elemento.str_legajo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("legajo")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("iniciales"))) = False Then
                Elemento.str_iniciales = (obj_Reader.GetValue(obj_Reader.GetOrdinal("iniciales")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idsector"))) = False Then
                Elemento.int_idsector = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idsector")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idcargo"))) = False Then
                Elemento.int_idcargo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idcargo")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idtercero"))) = False Then
                Elemento.int_idtercero = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idtercero")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("fechaingreso"))) = False Then
                Elemento.dte_fechaingreso = (obj_Reader.GetValue(obj_Reader.GetOrdinal("fechaingreso")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("fechaegreso"))) = False Then
                Elemento.dte_fechaegreso = (obj_Reader.GetValue(obj_Reader.GetOrdinal("fechaegreso")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("numerointerno"))) = False Then
                Elemento.str_numerointerno = (obj_Reader.GetValue(obj_Reader.GetOrdinal("numerointerno")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("valorhora"))) = False Then
                Elemento.dec_valorhora = (obj_Reader.GetValue(obj_Reader.GetOrdinal("valorhora")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("fechanacimiento"))) = False Then
                Elemento.dte_fechanacimiento = (obj_Reader.GetValue(obj_Reader.GetOrdinal("fechanacimiento")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idgerencia"))) = False Then
                Elemento.int_idgerencia = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idgerencia")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("jornada"))) = False Then
                Elemento.int_jornada = (obj_Reader.GetValue(obj_Reader.GetOrdinal("jornada")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("contratado"))) = False Then
                Elemento.bol_contratado = (obj_Reader.GetValue(obj_Reader.GetOrdinal("contratado")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idproveedor"))) = False Then
                Elemento.int_idproveedor = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idproveedor")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idcentrocostoorden"))) = False Then
                Elemento.int_idcentrocostoorden = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idcentrocostoorden")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("observacionesinterno"))) = False Then
                Elemento.str_observacionesinterno = (obj_Reader.GetValue(obj_Reader.GetOrdinal("observacionesinterno")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("cuño"))) = False Then
                Elemento.str_cuño = (obj_Reader.GetValue(obj_Reader.GetOrdinal("cuño")))
            End If

            col_Items.Add(Elemento)
        End While
    End Sub

    Private Sub CargarVariables(ByVal obj_Reader As SqlDataReader)
        obj_Reader.Read()
        int_idpersonal = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idpersonal")))

        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("legajo"))) = False Then
            str_legajo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("legajo")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("iniciales"))) = False Then
            str_iniciales = (obj_Reader.GetValue(obj_Reader.GetOrdinal("iniciales")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idsector"))) = False Then
            int_idsector = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idsector")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idcargo"))) = False Then
            int_idcargo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idcargo")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idtercero"))) = False Then
            int_idtercero = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idtercero")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("fechaingreso"))) = False Then
            dte_fechaingreso = (obj_Reader.GetValue(obj_Reader.GetOrdinal("fechaingreso")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("fechaegreso"))) = False Then
            dte_fechaegreso = (obj_Reader.GetValue(obj_Reader.GetOrdinal("fechaegreso")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("numerointerno"))) = False Then
            str_numerointerno = (obj_Reader.GetValue(obj_Reader.GetOrdinal("numerointerno")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("valorhora"))) = False Then
            dec_valorhora = (obj_Reader.GetValue(obj_Reader.GetOrdinal("valorhora")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("fechanacimiento"))) = False Then
            dte_fechanacimiento = (obj_Reader.GetValue(obj_Reader.GetOrdinal("fechanacimiento")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idgerencia"))) = False Then
            int_idgerencia = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idgerencia")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("jornada"))) = False Then
            int_jornada = (obj_Reader.GetValue(obj_Reader.GetOrdinal("jornada")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("contratado"))) = False Then
            bol_contratado = (obj_Reader.GetValue(obj_Reader.GetOrdinal("contratado")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idproveedor"))) = False Then
            int_idproveedor = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idproveedor")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idcentrocostoorden"))) = False Then
            int_idcentrocostoorden = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idcentrocostoorden")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("observacionesinterno"))) = False Then
            str_observacionesinterno = (obj_Reader.GetValue(obj_Reader.GetOrdinal("observacionesinterno")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("cuño"))) = False Then
            str_cuño = (obj_Reader.GetValue(obj_Reader.GetOrdinal("cuño")))
        End If
    End Sub

    Public Function Nuevo(Optional ByVal ObtenerID As Boolean = False) As Boolean
        Nuevo = False
        Dim obj_Conexion As New cls_Conexion
        Try

            'Creacion de Tercero----------------------------------------------------
            If idtercero = 0 Then
                tercero.Nuevo()
                idtercero = obj_tercero.idtercero
            End If
            '-----------------------------------------------------------------------

            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "personal__Nuevo"
                .Parameters.Add("@legajo", SqlDbType.NVarChar).Value = str_legajo
                .Parameters.Add("@iniciales", SqlDbType.NVarChar).Value = str_iniciales
                .Parameters.Add("@idsector", SqlDbType.Int).Value = IIf(int_idsector = 0, DBNull.Value, int_idsector)
                .Parameters.Add("@idcargo", SqlDbType.Int).Value = IIf(int_idcargo = 0, DBNull.Value, int_idcargo)
                .Parameters.Add("@fechaingreso", SqlDbType.DateTime).Value = dte_fechaingreso
                .Parameters.Add("@fechaegreso", SqlDbType.DateTime).Value = dte_fechaegreso
                .Parameters.Add("@idtercero", SqlDbType.Int).Value = int_idtercero
                .Parameters.Add("@numerointerno", SqlDbType.NVarChar).Value = str_numerointerno
                .Parameters.Add("@valorhora", SqlDbType.Decimal).Value = dec_valorhora
                .Parameters.Add("@fechanacimiento", SqlDbType.DateTime).Value = dte_fechanacimiento
                .Parameters.Add("@idgerencia", SqlDbType.Int).Value = int_idgerencia
                .Parameters.Add("@jornada", SqlDbType.Int).Value = int_jornada
                .Parameters.Add("@contratado", SqlDbType.Bit).Value = bol_contratado
                .Parameters.Add("@idproveedor", SqlDbType.Int).Value = int_idproveedor
                .Parameters.Add("@idcentrocostoorden", SqlDbType.Int).Value = IIf(int_idcentrocostoorden = 0, DBNull.Value, int_idcentrocostoorden)
                .Parameters.Add("@observacionesinterno", SqlDbType.NVarChar).Value = str_observacionesinterno
                .Parameters.Add("@cuño", SqlDbType.NVarChar).Value = str_cuño
                .ExecuteNonQuery()
            End With
            Nuevo = True
            If ObtenerID Then
                CargarUltimo()
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Crear el registro de personal_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Function

    Public Sub Modificar()
        Dim obj_Conexion As New cls_Conexion
        Try

            'Modificacion de Tercero------------------------------------------------
            obj_tercero.Modificar()
            '-----------------------------------------------------------------------

            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "personal__Modificar"
                .Parameters.Add("@idpersonal", SqlDbType.Int).Value = int_idpersonal
                .Parameters.Add("@legajo", SqlDbType.NVarChar).Value = str_legajo
                .Parameters.Add("@iniciales", SqlDbType.NVarChar).Value = str_iniciales
                .Parameters.Add("@idsector", SqlDbType.Int).Value = IIf(int_idsector = 0, DBNull.Value, int_idsector)
                .Parameters.Add("@idcargo", SqlDbType.Int).Value = IIf(int_idcargo = 0, DBNull.Value, int_idcargo)
                .Parameters.Add("@fechaingreso", SqlDbType.DateTime).Value = dte_fechaingreso
                .Parameters.Add("@fechaegreso", SqlDbType.DateTime).Value = dte_fechaegreso
                .Parameters.Add("@idtercero", SqlDbType.Int).Value = int_idtercero
                .Parameters.Add("@numerointerno", SqlDbType.NVarChar).Value = str_numerointerno
                .Parameters.Add("@valorhora", SqlDbType.Decimal).Value = dec_valorhora
                .Parameters.Add("@fechanacimiento", SqlDbType.DateTime).Value = dte_fechanacimiento
                .Parameters.Add("@idgerencia", SqlDbType.Int).Value = int_idgerencia
                .Parameters.Add("@jornada", SqlDbType.Int).Value = int_jornada
                .Parameters.Add("@contratado", SqlDbType.Bit).Value = bol_contratado
                .Parameters.Add("@idproveedor", SqlDbType.Int).Value = int_idproveedor
                .Parameters.Add("@idcentrocostoorden", SqlDbType.Int).Value = IIf(int_idcentrocostoorden = 0, DBNull.Value, int_idcentrocostoorden)
                .Parameters.Add("@observacionesinterno", SqlDbType.NVarChar).Value = str_observacionesinterno
                .Parameters.Add("@cuño", SqlDbType.NVarChar).Value = str_cuño
                .ExecuteNonQuery()
            End With
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Modificar el registro de personal_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Sub Eliminar(ByVal idpersonal As Integer)
        Dim obj_Conexion As New cls_Conexion
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "personal__Eliminar"
                .Parameters.Add("@idpersonal", SqlDbType.Int).Value = idpersonal
                .ExecuteNonQuery()
            End With
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Eliminar el registro de personal_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Function Buscar(ByVal idpersonal As Integer) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            Buscar = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "personal__Buscar"
                .Parameters.Add("@idpersonal", SqlDbType.Int).Value = idpersonal
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
                Buscar = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Buscar el registro de personal_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function
    Public Function BuscarXidtercero(ByVal idtercero As Integer) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            BuscarXidtercero = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "personal__buscarXidtercero"
                .Parameters.Add("@idtercero", SqlDbType.Int).Value = idtercero
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
                BuscarXidtercero = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al BuscarXidtercero el registro de personal_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function
    Public Function BuscarXcuño(ByVal prm_cuño As String) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            BuscarXcuño = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "personal__buscarXcuño"
                .Parameters.Add("@cuño", SqlDbType.NVarChar).Value = prm_cuño
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
                BuscarXcuño = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al BuscarXcuño el registro de personal_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function
    Public Sub CargarUltimo()
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "personal__CargarUltimo"
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al CargarUltimo registro de personal_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Sub

    Public Function CargarTodos(Optional ByVal idregistroestado As Integer = 1) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarTodos = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "personal__CargarTodos"
                .Parameters.Add("@idregistroestado", SqlDbType.Int).Value = idregistroestado
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarTodos = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al CargarTodos los registros de personal_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Function CargarXidproceso(ByRef idproceso As Integer) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarXidproceso = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "personal__CargarXidproceso"
                .Parameters.Add("@idproceso", SqlDbType.Int).Value = idproceso
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarXidproceso = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al CargarTodos los registros de personal_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function
    Public Function CargarXidcargo(ByRef idcargo As Integer) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarXidcargo = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "personal__CargarXidcargo"
                .Parameters.Add("@idcargo", SqlDbType.Int).Value = idcargo
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarXidcargo = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al CargarXidcargo los registros de personal_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function
    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim obj_personal_Clon As New cls_personal_
        obj_personal_Clon.int_idpersonal = Me.int_idpersonal
        obj_personal_Clon.str_legajo = Me.str_legajo
        obj_personal_Clon.str_iniciales = Me.str_iniciales
        obj_personal_Clon.int_idsector = Me.int_idsector
        obj_personal_Clon.int_idcargo = Me.int_idcargo
        obj_personal_Clon.int_idtercero = Me.int_idtercero
        obj_personal_Clon.dte_fechaingreso = Me.dte_fechaingreso
        obj_personal_Clon.dte_fechaegreso = Me.dte_fechaegreso
        obj_personal_Clon.str_numerointerno = Me.str_numerointerno
        obj_personal_Clon.dec_valorhora = Me.dec_valorhora
        obj_personal_Clon.dte_fechanacimiento = Me.dte_fechanacimiento
        obj_personal_Clon.int_idgerencia = Me.int_idgerencia
        obj_personal_Clon.col_Items = Me.col_Items
        Return obj_personal_Clon
    End Function

End Class
